<!DOCTYPE html>
<html>
<head>
  <title>欢迎登录</title>
  <link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css">
  <script type="text/javascript" src="/js/jquery.min.js"></script>
</head>
<body>
      <div class="container" style="margin-top:180px; ">

        <div class="col-md-6 col-md-offset-3">
            <div class="panel panel-primary">
                <div class="panel-heading">登录学生管理系统</div>
                <div class="panel-body">
                   <div class="form-horizontal">
                        <div class="form-group">
                            <label for="uname" class="col-sm-2 control-label">用户名</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="username" id="usernameId" placeholder="请输入用户名">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pwd" class="col-sm-2 control-label">密码</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" name="password" id="passwordId" placeholder="请输入密码">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pwd" class="col-sm-2 control-label">验证码</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" name="vcode" id="vcodeId" placeholder="请输入验证码">
                            </div>
                            <div class="col-sm-3">
                                <img id="vcodeimg" src="/account/vcode">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <!-- submit有一个默认的提交行为，不要加上 -->
                                <!-- <button type="submit" onclick="login()"  class="btn btn-default">登录</button> -->
                                <button onclick="login()"  class="btn btn-default">登录</button>
                                &nbsp;&nbsp;
                                <input  onclick="register();" type="button"  value="注册" class="btn btn-danger">
                            </div>
                        </div>
                   </div>
                </div>
            </div>
            </div>
    </div>
</body>
<script type="text/javascript">
    $("#vcodeimg").click(function(){
        //如果我们发送的是GET请求，如果地址不变，就不会发送请求
        $("#vcodeimg").attr('src','/account/vcode?'+Math.random())
    })

    //登录
    function login(){
            //使用$.post 进行登录操作
            var url = 'http://192.168.117.81:3000/account/login'
            $.post(url,{username:$("#usernameId").val(),password:$("#passwordId").val(),vcode:$("#vcodeId").val()},function(jsObj){
                if (jsObj.status == 1){
                    alert(jsObj.message)
                }
            })
    }
</script>
</html>
